package com.ysd.dao.Impl;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import com.ysd.entity.Admin;
import com.ysd.util.DBManager;

public class AdminDaoImpl {
	/***
	 * 根据账号查询信息
	 * @param username
	 * @return
	 */
     public Admin getAdminByUsername(String username) {
    	 Admin admin=null;
    	 Connection conn=DBManager.getConnection();
    	 Statement st=null;
    	 ResultSet rs=null;
    	 try {
			st=conn.createStatement();
			rs=st.executeQuery("SELECT * FROM admin WHERE username='"+username+"'");
			while(rs.next()) {
				int id=rs.getInt(1);
				String uname=rs.getString(2);
				String password=rs.getString(3);
			    admin=new Admin(id, username, password);//构造方法是用来创造对象的当new时被调用
			}
			return admin;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
     }
}
